﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data;

namespace VietKinsNutrition.Data
{
    public class ClsTblDm_LoaikienthucnoitroDAL
    {
        //Procedure 
        ClsBindingBLL ClsBin = new ClsBindingBLL();
        //ClsConnection ClsCnn = new ClsConnection();
        public DataSet FindSameName(string VarTen)
        {
            string NamePrc = QueryString.TBLDM_LOAIMON_FINDNAMESAMEPRC;
            string NameTable = "TblDm_Loaimon";
            DataSet Dset = new DataSet();
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;

            DataColumn Columm = new DataColumn();
            Columm.ColumnName = Columm.Caption = "STT";
            Columm.DataType = System.Type.GetType("System.Int32");
            Columm.AllowDBNull = false;
            Columm.AutoIncrement = true;
            Columm.AutoIncrementSeed = Columm.AutoIncrementStep = 1;
            NewTable.Columns.Add(Columm);
            Dset.Tables.Add(NewTable);

            OleDbCommand Cmm = new OleDbCommand();
            Cmm.Parameters.Add(new OleDbParameter("@VarTen", VarTen));

            Cmm.Connection = ClsConnection.OleDBConnect();
            Cmm.CommandText = NamePrc;
            //Cmm.CommandType = CommandType.StoredProcedure;
            try
            {
                if (Cmm.Connection.State != ConnectionState.Open) Cmm.Connection.Open(); Cmm.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
            }
            finally
            {
                Cmm.Connection.Close();
            }
            OleDbDataAdapter Dap;
            Dap = new OleDbDataAdapter(Cmm);
            Dap.Fill(Dset.Tables[NameTable]);

            return Dset;
        }
        public DataTable SelectAll()
        {
            string NamePrc = QueryString.SP_LOAIKIENTHUCNOITRO_GET;
            string NameTable = "TblDm_Loaikienthucnoitro";
            DataTable NewTable = new DataTable();
            NewTable.TableName = NameTable;


            DataColumn Columm = new DataColumn();
            Columm.ColumnName = Columm.Caption = "STT";
            Columm.DataType = System.Type.GetType("System.Int32");
            Columm.AllowDBNull = false;
            Columm.AutoIncrement = true;
            Columm.AutoIncrementSeed = Columm.AutoIncrementStep = 1;
            NewTable.Columns.Add(Columm);

            ClsBindingBLL.OleDBSelectAll(NamePrc).Fill(NewTable);

            return NewTable;

        }
        public void Insert(string Ten)
        {
            string NamePrc = QueryString.SP_LOAIKIENTHUCNOITRO_ADD;
            OleDbCommand Cmm = new OleDbCommand();

            OleDbParameter Ten_Paramet = new OleDbParameter();

            Ten_Paramet.ParameterName = "@Tenloaikienthucnoitro";
            Ten_Paramet.OleDbType = System.Data.OleDb.OleDbType.VarWChar;
            Ten_Paramet.Value = Ten;

            Cmm.Parameters.Add(Ten_Paramet);
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
        }
        public void Edit(int Id, string Ten)
        {
            //string NamePrc = QueryString.SP_LOAIKIENTHUCNOITRO_UPDATE;
            string NamePrc = "UPDATE TblDm_Loaikienthucnoitro SET Tenloaikienthucnoitro = '" + Ten + "' WHERE Id=" + Id;
            OleDbCommand Cmm = new OleDbCommand();
            ClsConnection.OleDbDAdpter(NamePrc, Cmm);
            Cmm.Connection.Close();
        }
        public void Del(int Id)
        {
            string NamePrc = QueryString.SP_LOAIKIENTHUCNOITRO_DEL;
            OleDbCommand Cmm = new OleDbCommand();
            OleDbParameter Id_Paramet = new OleDbParameter();
            OleDbParameter Ten_Paramet = new OleDbParameter();

            Id_Paramet.ParameterName = "@Id";
            Id_Paramet.OleDbType = OleDbType.Integer;
            Id_Paramet.Value = Id;

            Cmm.Parameters.Add(Id_Paramet);

            ClsConnection.OleDbDAdpter_Del(NamePrc, Cmm);

        }
    }
}
